<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
<link rel="stylesheet" href="../../lib/layui/css/layui.css" media="all">
    <style>
        .form-wrap{
            padding: 10px;
        }
    </style>
</head>
<body>
<div class="form-wrap">
    <!-- 新建门店表单 -->
    <form id="store_form" class="layui-form" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">门店名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">门店地址</label>
            <div class="layui-input-block">
                <input type="text" name="address" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">门店电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">门店经度</label>
            <div class="layui-input-block">
            	<input type="text" name="longitude" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">门店纬度</label>
            <div class="layui-input-block">
                <input type="text" name="latitude" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">门店规模</label>
            <div class="layui-input-block">
                <input type="text" name="scale" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">营业时间</label>
            <div class="layui-input-block">
				<input type="text" name="openHours" lay-verify="required"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开业日期</label>
            <div class="layui-input-block">
                <input type="text" name="createTime" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
            	<textarea name="note" placeholder="备注" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <select name="status">
					<option value="1">正常</option>
					<option value="0">禁用</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block"> 
                <button class="layui-btn" type="button" onclick="storeForm.submit()">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
    <script src="../../publicjs/jquery-1.8.0.min.js"></script>
    <script src="../../publicjs/smallkingutil.js"></script>
    <script src="../../lib/layui/layui.js"></script>
<script type="text/javascript">

layui.use(['form', 'laydate'], function(){
        var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate;
        // 初始化layui的日期控件
        laydate.render({
            elem: '#date'
        });
        
    	window.storeForm = {
    		submit : function() {
    			var storeForm = document.getElementById("store_form");
    			var formData = new FormData(storeForm);
    			var	url = commonUtil.domain() +"/admin/mall/store/insert";
    			var	msg = "新增";
    			if(this.storeId){
    				url = commonUtil.domain() +"/admin/mall/store/update";
    				msg = "修改";
    				formData.set("storeId", this.storeId);
    			}
    			var ajaxParam = {
    				url : url
    			}
    			ajaxUtil.submitForm(formData, ajaxParam, function(data) {
    				if (data.code == 200) {
    					// 关闭当前的表单弹窗 刷新父级页面的数据表格
    					var parentHtml = window.parent;
    					parentHtml.layer.closeAll();
    					parentHtml.storeTable.refresh();
    				} else {
    					layer.msg(msg + "失败，请联系开发人员。");
    				}
    			});
    		}
    	}
    	var storeId = commonUtil.getRequestParam("storeId");
    	if (storeId){
    		storeForm.storeId = storeId;
    		// 请求后台得到当前修改的用户数据，将其显示在表单里
    		var ajaxParam = {
    			url : commonUtil.domain() +'/admin/mall/store/detail',
    			data : {
    				storeId : storeId
    			}
    		}
    		ajaxUtil.post(ajaxParam, function(data) {
    			formUtil.setForm($('#store_form'), data.data);
    		});
    	}
    });
</script>
<script>
	$(function(){
				commonUtil.setMaxLength(40);
			})
</script>
</body>
</html> 